﻿using FastMvc.Auth;
using FastMvc.Crud;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Text;
using JQ.SAAS.Entity;
using JQ.SAAS.DTO.OrgRole;
using JQ.SAAS.IService;
using System.Threading.Tasks;
using FastMvc.Models;

namespace JQ.SAAS.WebServer.Controllers
{
    /// <summary>
    /// 机构角色管理
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [PermissionCheck("Admin.Org.Role", "机构角色管理")]
    public class OrgRoleController : CrudController<org_role, OrgRoleDto, string, OrgRoleListRequestDto, OrgRoleCreateUpdateDto, OrgRoleCreateUpdateDto>    
    {
        private IOrgRoleService _orgRoleService;

        public OrgRoleController(IOrgRoleService orgRoleService)
            : base(orgRoleService)
        {
            this._orgRoleService = orgRoleService;
        }

        /// <summary>
        /// 获取指定角色的菜单列表
        /// </summary>
        [HttpGet("{sId}/menus")]
        [PermissionCheck("MenusSet", "配置菜单")]
        public async Task<BaseResult<List<OrgRoleMenuSetDto>>> GetRoleMenus(string sId)
        {
            var list = await _orgRoleService.GetRoleMenus(sId);

            return await SetResultNotNull(list);
        }

        /// <summary>
        /// 设置指定角色的菜单列表
        /// </summary>
        /// <returns></returns>
        [HttpPost("{sId}/menus")]
        [PermissionCheck("MenusSet", "配置菜单")]
        public async Task<BaseResult> SetRoleMenus(string sId,[FromBody]List<OrgRoleMenuSetDto> menus)
        {
            await _orgRoleService.SetRoleMenus(sId, menus);
            return BaseResult.Success("设置成功!");
        }
    }
}
